<?php

namespace App\Models\Loginserver;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\Loginserver\AccountData
 *
 * @property int $id
 * @property string $name
 * @property string $password
 * @property bool $activated
 * @property bool $access_level
 * @property bool $membership
 * @property bool $old_membership
 * @property bool $last_server
 * @property string|null $last_ip
 * @property string $last_mac
 * @property string|null $ip_force
 * @property string|null $expire
 * @property int $toll
 * @property int $shop_points
 * @property string|null $email
 * @property string|null $pushbullet
 * @property string|null $question
 * @property string|null $answer
 * @property float|null $balance
 * @property int $luna
 * @property bool $return_account
 * @property string $return_end
 * @property string|null $pseudo
 * @property int $vote
 * @property string|null $token
 * @property \App\Models\Loginserver\AccountLevel $level
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Gameserver\Player[] $players
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData activated()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData addShopPoints($accountId, $quantity)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData incrementVoteCount($accountId)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData me($accountId)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData whereAccessLevel($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData whereActivated($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData whereAnswer($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData whereBalance($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData whereEmail($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData whereExpire($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData whereIpForce($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData whereLastIp($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData whereLastMac($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData whereLastServer($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData whereLevel($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData whereLuna($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData whereMembership($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData whereOldMembership($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData wherePassword($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData wherePseudo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData wherePushbullet($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData whereQuestion($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData whereReturnAccount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData whereReturnEnd($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData whereShopPoints($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData whereToken($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData whereToll($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Loginserver\AccountData whereVote($value)
 * @mixin \Eloquent
 */
class AccountData extends Model
{

    protected $table = 'account_data';
    protected $connection = 'loginserver';
    protected $fillable = ['id', 'name', 'password', 'email', 'shop_points', 'vote', 'pseudo', 'token', 'pushbullet'];
    public $timestamps = false;

    /**
     * @param $query
     * @return Builder
     */
    public function scopeActivated(Builder $query)
    {
        return $query->where('activated', 1);
    }

    /**
     * Increment Shop points
     *
     * @param $query
     * @param $accountId
     * @param $quantity
     *
     * @return
     */
    public function scopeAddShopPoints($query, $accountId, $quantity)
    {
        return $query->where('id', $accountId)->increment('shop_points', $quantity);
    }

    /**
     * Add in Scope function for vote
     *
     * @param $query
     *
     * @param $accountId
     *
     * @return
     */
    public function scopeIncrementVoteCount($query, $accountId)
    {
        return $query->where('id', $accountId)->increment('vote');
    }

    /**
     * Add in Scope function for select Me account
     *
     * @param $query
     * @param $accountId
     *
     * @return
     */
    public function scopeMe($query, $accountId)
    {
        return $query->where('id', $accountId);
    }

    /**
     * Get players of account
     */
    public function players()
    {
        return $this->hasMany('App\Models\Gameserver\Player', 'account_id', 'id');
    }

    /**
     * Return account level
     */
    public function level()
    {
        return $this->belongsTo('App\Models\LoginServer\AccountLevel', 'account_id', 'id');
    }

}
